package com.hulu.yec.qes.service;

import java.util.List;

import com.hulu.yec.qes.entity.QesPaperEntity;
import com.hulu.yec.qes.util.DBUtil;
import com.hulu.yec.teach.testquestion.enetity.QuestionEntity;

public class QesPaperService {

	public QesPaperEntity detailselect(int parseInt) {
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT p.paper_type,  p.paper_url, p.id, p.`name`,c.`name` as 'sys_course$name', p.paper_type, p.course_id, p.total_point, p.pass_point, p.total_minutes, p.single_option_number, p.single_option_each_point, ");
		sb.append("p.single_option_difficulty, p.multi_option_number, p.multi_option_each_point, p.multi_option_difficulty, p.judge_number, p.judge_each_point, p.judge_difficulty, u.`name` as 'sys_user$name', p.opreate_time, p.state, p.memo ");
		sb.append("FROM qes_exam_paper p,sys_course c,sys_user u ");
		sb.append("WHERE p.course_id=c.id AND p.opreate_user_id=u.id AND p.id = ?");
		return DBUtil.getUniqueResult(QesPaperEntity.class, sb.toString(), parseInt);
	}

	/**
	 * 添加json文件路径到数据库中
	 * @param paperUrl
	 * @param paperId
	 * @return
	 */
	public int addPaperUrl(String paperUrl, int paperId) {
		String sql = "update qes_exam_paper set paper_url=? where id=?";
		return DBUtil.executeUpdate(sql,paperUrl,paperId);
	}

	/**
	 * 根据试卷信息生成符合试卷信息的试卷题目组成的id集合
	 * @param courseType 
	 * @param questionType 
	 * @param questionDifficulty
	 * @return List<Integer>
	 */
	public List<QuestionEntity> getQestions( int questionType, int questionNumber) {
		String sql = "SELECT * FROM qes_qestions where question_type = ? GROUP BY RAND() LIMIT ?";
		List<QuestionEntity> qestions = DBUtil.executeQuery(QuestionEntity.class, sql, questionType, questionNumber);
		return qestions;
	}

}
